<?php

/**
 * goods模型
 * @author 
 * @version 1.0
 * @package application
 * @subpackage application/models
 */
class Goods_Model extends MY_Model {

    public function __construct() {
        parent::__construct();
        $this->_pk = 'goods_id';
        $this->_attributes = array(
            'goods_id' => '',
            'goods_name' => '',
            'gc_id' => '',
            'gc_name' => '',
            'brand_id' => '',
            'type_id' => '',
            'store_id' => '',
            'spec_open' => '',
            'spec_id' => '',
            'spec_name' => '',
            'goods_image' => '',
            'goods_image_more' => '',
            'goods_store_price' => '',
            'goods_store_price_interval' => '',
            'goods_serial' => '',
            'goods_show' => '',
            'goods_click' => '',
            'goods_state' => '',
            'goods_commend' => '',
            'goods_add_time' => '',
            'goods_keywords' => '',
            'goods_description' => '',
            'goods_body' => '',
            'goods_attr' => '',
            'goods_spec' => '',
            'goods_col_img' => '',
            'goods_indate' => '',
            'goods_starttime' => '',
            'goods_endtime' => '',
            'goods_form' => '',
            'transport_id' => '',
            'py_price' => '',
            'kd_price' => '',
            'es_price' => '',
            'city_id' => '',
            'province_id' => '',
            'goods_close_reason' => '',
            'commentnum' => '',
            'salenum' => '',
            'group_flag' => '',
            'goods_transfee_charge' => '',
            'created' => '',
            'modified' => '',
            'status' => '',
        );
    }

    public function update_click($id) {
        $this->db->set('goods_click', 'goods_click+1', FALSE); //阻止转义，去掉字段中的单引号。即 UPDATE `Goods` SET `goods_click` = goods_click+1 WHERE `goods_id` =  '1'  
        $this->db->where($this->primary_key(), $id)->update($this->table_name());
    }

    //上一篇
    public function pre_goods($pid, $id) {
        $query = $this->db->select($this->get_datas_str())->from($this->table_name())
                        ->where(array('gc_id' => $pid, 'goods_id <' => $id))//id与>之间要有空格
                        ->order_by("goods_id", "desc")->limit(1, 0);
        return $query->get()->row_array();
    }

    //下一篇
    public function next_goods($pid, $id) {
        $query = $this->db->select($this->get_datas_str())->from($this->table_name())
                        ->where(array('gc_id' => $pid, 'goods_id >' => $id))//id与>之间要有空格
                        ->order_by("goods_id", "asc")->limit(1, 0);
        return $query->get()->row_array();
    }

}
